package com.xinchuang.initializrdemo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;



@Configuration // 告诉springboot 这是一个配置类
public class WebMvcConfigurerOverride implements WebMvcConfigurer {
    /**
     * 跨域配置
     * @param corsRegistry
     */
    @Override
    public void addCorsMappings(CorsRegistry corsRegistry){
        corsRegistry.addMapping("/**")
                // 请求头
                .allowedHeaders("*")
                // 方法
                .allowedMethods("GET","POST","PUT","DELETE","OPTIONS")
                // 地址
                .allowedOriginPatterns("*")
                // 允许cookie /
                .allowCredentials(true)
                .maxAge(3600);
    }
}
